package com.woniuxy.classteacher.service.impl;

import com.woniuxy.classteacher.mapper.StudentMapper;
import com.woniuxy.classteacher.service.QuitSchoolService;
import com.woniuxy.commons.entity.StudentInfo;
import com.woniuxy.commons.entity.wyh.GradeInfo;
import com.woniuxy.commons.entity.wyh.TeamInfo;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 李英勇
 * @date 2020/7/28 - 16:10
 */
@Service
public class QuitSchoolServiceImpl implements QuitSchoolService {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Autowired
    private StudentMapper studentMapper;


    /**
     * @Author: 李英勇
     * @Description: 异步通知年级主任退学学生的id
     * @DateTime: 2020/7/28 16:36
     * @Params: [sid]
     * @Return void
     */
    @Override
    public void doQuitForStu(Integer sid) {
        //通过sid获取学生的年级信息
        StudentInfo studentInfo = studentMapper.findStuByStuid(sid);
        TeamInfo teamInfo = studentInfo.getTeamInfo();
        GradeInfo gradeInfo = teamInfo.getGradeInfo();
        String gradeType = gradeInfo.getGradeType();

        System.out.println(sid + ":" + gradeType);

        if ("高一".equals(gradeType)) {
            rabbitTemplate.convertAndSend("directExchange", "高一", sid);
        } else if ("高二".equals(gradeType)) {
            rabbitTemplate.convertAndSend("directExchange", "高二", sid);
        } else if ("高三".equals(gradeType)) {
            rabbitTemplate.convertAndSend("directExchange", "高三", sid);
        }

    }
}
